#ifndef 	_COM_HASH_H_
#define _COM_HASH_H_
#include "mrc_base.h"
#include "heap.h"

#define MEM_MALLOC        mrc_malloc
#define MEM_FREE             mrc_free

typedef uint32 magic_t;

typedef struct HASH_ENTRY {
magic_t magic;
void *private;
struct HASH_ENTRY *next;
} HASH_ENTRY_T;

typedef struct HASH_HEAD {
struct HASH_ENTRY *head;
struct HASH_ENTRY *tail;
} HASH_HEAD_T; 

typedef struct{
int32 tableSize;
int32 searchIndex;
HASH_ENTRY_T* searchEntry;
HASH_HEAD_T magicList[1]; 
}HASH_T;

#define HASH_TABLE_SIZE(table) ((table!=0)?table->tableSize:-1)
#define HASH_NEXT_ITEM(presntItem) ((presntItem!=0)?presntItem->next:0)
#define HASH_PRIV(presntItem) ((presntItem!=0)?presntItem->private:0)
#define HASH_MAGIC(presntItem) ((presntItem!=0)?presntItem->magic:0)


HASH_T * hash_create(int32 tableSize);
int32 hash_dataClear(HASH_T *hashTable, uint32 freeData);
void hash_destroy(HASH_T *hashTable);
void *hash_findData(HASH_T *hashTable, uint32 magic);
int32 hash_addItem(HASH_T *hashTable, void *priv, uint32 magic);
int32 hash_removeItem(HASH_T *hashTable, uint32 magic);

HASH_ENTRY_T* hash_firstItem(HASH_T *hashTable, int32 index);
void* hash_searchDataFirst(HASH_T *hashTable);
void* hash_searchDataNext(HASH_T *hashTable);
	
#endif
